//
//  DBJIllnessCaseManageViewController.m
//  DBJ
//
//  Created by 花化华 on 2016/11/12.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "DBJIllnessCaseManageViewController.h"
#import "DBJIIllnewwCaseUseProfileView.h"
#import "DBJIllnessSecondView.h"
#import "DBJAddIllCaseViewController.h"
#import "DBJAddIllCaseTableViewController.h"
@interface DBJIllnessCaseManageViewController ()<DBJIllnessSecondViewDelegate,DBJAddIllCaseTableViewControllerDelegate,cellPushTabControllerdelegate>

/* 记录secondeViews */
@property(nonatomic,weak)DBJIllnessSecondView *senondVIews;

@end

@implementation DBJIllnessCaseManageViewController


/*重写设置UI界面方法*/
- (void)dbjSetupSubviews{
    [super dbjSetupSubviews];
    
    self.view.backgroundColor=[UIColor grayColor];
    
    //添加用户信息视图
    DBJIIllnewwCaseUseProfileView *userView=[[DBJIIllnewwCaseUseProfileView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 184)];
    [self.view addSubview:userView];
    
    //添加病例管理下部视图
    DBJIllnessSecondView *secondView=[[DBJIllnessSecondView alloc]initWithFrame:CGRectZero];
    [self.view addSubview:secondView];
    secondView.delegate=self;   //添加代理对象
    self.senondVIews=secondView;
    self.senondVIews.illList=[self unarch];
    
    //添加病例管理下部视图约束
    [secondView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
//        make.top.equalTo(userView.mas_bottom);
    }];
    
}

#pragma mark -实现DBJIllnessSecondViewDelegate的代理方法

-(void)IllSecondViewWithView:(DBJIllnessSecondView *)secondView{
    
    DBJAddIllCaseTableViewController *addCaseVC=[[DBJAddIllCaseTableViewController alloc]init];
    addCaseVC.delegate=self;
    self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemCancel target:nil action:nil];
    addCaseVC.title=@"添加病历";
    [self.navigationController pushViewController:addCaseVC animated:YES];
    
}

#pragma mark -cellPushTabControllerdelegate代理方法序号

-(void)cellpushVCWithModel:(DBJSecondTabModel *)model andRow:(NSInteger)row{
    
    DBJAddIllCaseTableViewController *addCaseVC=[[DBJAddIllCaseTableViewController alloc]init];
    addCaseVC.delegate=self;
    self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemCancel target:nil action:nil];
    addCaseVC.secondTabmodel=model;
    addCaseVC.title=@"添加病历";
    addCaseVC.row=row;
    [self.navigationController pushViewController:addCaseVC animated:YES];
    
}

#pragma mark -DBJAddIllCaseTableViewControllerDelegate代理方法

-(void)popControllerWithVC:(DBJAddIllCaseTableViewController *)Controller{
    
   //解档本地数据
//    NSString *docuPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
//    NSString *fliePth= [docuPath stringByAppendingPathComponent:@"ill.nb"];
//    
//    NSArray *list=[NSKeyedUnarchiver unarchiveObjectWithFile:fliePth];
//    NSLog(@"%@--%ld",list,list.count);
//    NSLog(@"xxixi ");
    self.senondVIews.illList=[self unarch];
    
}

//解档方法
-(NSArray *)unarch{
    NSString *docuPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSString *fliePth= [docuPath stringByAppendingPathComponent:@"ill.nb"];

    NSArray *list=[NSKeyedUnarchiver unarchiveObjectWithFile:fliePth];

    return list;
}

- (void)dbjSetupNavigationItems{
    [super dbjSetupNavigationItems];
}

@end
